package main

import (
	"context"
	"virtual_device/devices"

	"gitee.com/zhuhuan12/go-modbus/normal_conn"

	"github.com/gogf/gf/v2/frame/g"
)

func main() {
	usb := normal_conn.Usb{
		Com:  "/COM3",
		Baud: 9600,
	}
	usb.Conn(func(msgType, connId string, data []byte, msgSec int64) {
		backdata, err := devices.DataIn(data)
		if err != nil {
			g.Log().Warning(context.Background(), "数据处理失败", err)
			return
		}
		if len(backdata) == 0 {
			return
		}
		err = usb.SendMsg(backdata)
		if err != nil {
			g.Log().Warning(context.Background(), "usb口返回数据失败", err)
		}
		g.Log().Debug(context.Background(), "")
	})
	select {}
}
